//******************************************************************************
//  _____                  _    _             __
// |  _  |                | |  | |           / _|
// | | | |_ __   ___ _ __ | |  | | __ _ _ __| |_ __ _ _ __ ___
// | | | | '_ \ / _ \ '_ \| |/\| |/ _` | '__|  _/ _` | '__/ _ \
// \ \_/ / |_) |  __/ | | \  /\  / (_| | |  | || (_| | | |  __/
//  \___/| .__/ \___|_| |_|\/  \/ \__,_|_|  |_| \__,_|_|  \___|
//       | |               We don't make the game you play.
//       |_|                 We make the game you play BETTER.
//
//            Website: http://openwarfaremod.com/
//******************************************************************************

#include openwarfare\_eventmanager;
#include openwarfare\_utils;

init()
{
	// Get the main module's dvar
	level.scr_bodyremoval_enable = getModDvarX( "scr_bodyremoval_enable", "int", 0, 0, 3 );

	// If body removal is not enabled then there's nothing else to do here
	if ( level.scr_bodyremoval_enable == 0 || getModDvarX( "scr_dogtags_enable", "int", 0, 0, 1 ) == 1 )
		return;

	level.scr_bodyremoval_time = getModDvarX( "scr_bodyremoval_time", "float", 20, 5, 300 );
	level._effect["body_remove"] = loadfx( "explosions/fx_exp_equipment" );

	level thread addNewEvent( "onPlayerConnected", ::onPlayerConnected );
}


onPlayerConnected()
{

	self thread addNewEvent( "onPlayerKilled", ::onPlayerKilled );

}


onPlayerKilled()
{
	level endon( "game_ended" );
	
	// Save the body in case the player disconnects
	thisBody = self.body;
	
	// Wait the required time to remove the body
	xWait( level.scr_bodyremoval_time );
		
	// Remove the body if it's still there
	if ( isDefined( thisbody ) ) {

		switch ( level.scr_bodyremoval_enable ) {
                    
                       case 2:
                                wait (0.08);
				playfx( level._effect["body_remove"], thisBody.origin );
                                break;
	

                       case 3:
                                wait (0.08);			
                                playfx( level._effect["body_remove"], thisBody.origin );
                                wait (0.08);
                                PlaySoundAtPosition ( "dst_equipment_destroy", thisBody.origin );
                                break;
	       }
         
               thisBody delete();	
	}
}